/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef SHARED_BASE_EVENT_WIN32_H_
#define SHARED_BASE_EVENT_WIN32_H_

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>


class EventImpl
{
protected:
	EventImpl(bool bManualReset, bool bInitialState, const char *name);
	~EventImpl(void);

	bool setImpl(void);
	bool resetImpl(void);
	bool waitImpl(void);
	bool waitImpl(long milliseconds);

private:
	HANDLE _event;
};


inline bool EventImpl::setImpl(void)
{
	return SetEvent(_event) != FALSE;
}

inline bool EventImpl::resetImpl(void)
{
	return ResetEvent(_event) != FALSE;
}

inline bool EventImpl::waitImpl(void)
{
	return WaitForSingleObject(_event, INFINITE) != WAIT_FAILED;
}

inline bool EventImpl::waitImpl(long milliseconds)
{
	return WaitForSingleObject(_event, (DWORD)milliseconds) != WAIT_FAILED;
}

#endif /* SHARED_BASE_EVENT_WIN32_H_ */
